﻿Namespace DoFactory.GangOfFour.Proxy.Structural

    ''' <summary>
    ''' MainApp startup class for Structural
    ''' Proxy Design Pattern.
    ''' </summary>
    Public Class MainApp
        ''' <summary>
        ''' Entry point into console application.
        ''' </summary>
        Public Shared Sub Main()

            ' Create proxy and request a service
            Dim proxy As New Proxy()
            proxy.Request()

        End Sub

    End Class

    ''' <summary>
    ''' The 'Subject' abstract class
    ''' </summary>
    MustInherit Class Subject
        Public MustOverride Sub Request()
    End Class

    ''' <summary>
    ''' The 'RealSubject' class
    ''' </summary>
    Class RealSubject
        Inherits Subject

        Public Overrides Sub Request()
            Console.WriteLine("Called RealSubject.Request()")
        End Sub

    End Class

    ''' <summary>
    ''' The 'Proxy' class
    ''' </summary>
    Class Proxy
        Inherits Subject

        Private _realSubject As RealSubject

        Public Overrides Sub Request()
            ' Use 'lazy initialization'
            If _realSubject Is Nothing Then
                _realSubject = New RealSubject()
            End If

            _realSubject.Request()

        End Sub
    End Class

End Namespace
